#include<iostream>
#include<vector>

using namespace std;

class Solution {
public:
    vector<vector<int>> generateMatrix(int n) {
        vector<vector<int>> martix(n, vector<int>(n, 0));
        int num = 1;
        int layer = 0;
        while(num <= n * n){
            for(int i = layer; i < n - layer; i++){
                martix[layer][i] = num++;
            }
            for(int i = layer + 1; i < n - layer; i++){
                martix[i][n - layer -1] = num++;
            }
            for(int i = n - layer - 2; i >= layer ; i--){ // 判断条件用layer而不是0，不然到第二层的时候会被覆盖掉
                martix[n - layer - 1][i] = num++;
            }
            for(int i = n -layer -2; i > layer; i--){ // 同上
                martix[i][layer] = num++;
            }
            ++layer;
        }
        return martix;
    }
};

int main() {
    int n;
    cin >> n; 
    Solution s;

    vector<vector<int>> matrix = s.generateMatrix(n); // 生成矩阵

    // 打印矩阵
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}